using UnityEngine;

public class RCC_CreateAudioSource : MonoBehaviour
{
	public static AudioSource NewAudioSource(GameObject go, string audioName, float minDistance, float maxDistance, float volume, AudioClip audioClip, bool loop, bool playNow, bool destroyAfterFinished, bool ConstPlay, GameObject allAudioSources, GameObject ConstAudioSources)
	{
		GameObject gameObject = new GameObject(audioName);
		gameObject.transform.position = go.transform.position;
		gameObject.transform.rotation = go.transform.rotation;
		gameObject.transform.parent = go.transform;
		AudioSource audioSource = gameObject.AddComponent<AudioSource>();
		audioSource.minDistance = minDistance;
		audioSource.maxDistance = maxDistance;
		audioSource.volume = volume;
		audioSource.clip = audioClip;
		audioSource.loop = loop;
		if (minDistance == 0f && maxDistance == 0f)
		{
			audioSource.spatialBlend = 0f;
		}
		else
		{
			audioSource.spatialBlend = 1f;
		}
		if (playNow)
		{
			audioSource.playOnAwake = true;
			audioSource.Play();
		}
		else
		{
			audioSource.playOnAwake = false;
		}
		if (destroyAfterFinished)
		{
			if ((bool)audioClip)
			{
				Object.Destroy(gameObject, audioClip.length);
			}
			else
			{
				Object.Destroy(gameObject);
			}
		}
		if (ConstPlay)
		{
			if (ConstAudioSources != null)
			{
				gameObject.transform.SetParent(ConstAudioSources.transform);
			}
			else
			{
				GameObject gameObject2 = new GameObject("Const Audio Sources");
				gameObject2.transform.SetParent(go.transform, false);
				gameObject.transform.SetParent(gameObject2.transform, false);
				allAudioSources = gameObject2;
			}
		}
		else if (allAudioSources != null)
		{
			gameObject.transform.SetParent(allAudioSources.transform);
		}
		else
		{
			GameObject gameObject3 = new GameObject("All Audio Sources");
			gameObject3.transform.SetParent(go.transform, false);
			gameObject.transform.SetParent(gameObject3.transform, false);
			allAudioSources = gameObject3;
		}
		return audioSource;
	}

	public static AudioSource NewAudioSourceCrash(GameObject go, string audioName, float minDistance, float maxDistance, float volume, AudioClip audioClip, bool loop, bool playNow, bool destroyAfterFinished)
	{
		GameObject gameObject = new GameObject(audioName);
		gameObject.transform.position = go.transform.position;
		gameObject.transform.rotation = go.transform.rotation;
		gameObject.transform.parent = go.transform;
		AudioSource audioSource = gameObject.AddComponent<AudioSource>();
		audioSource.minDistance = minDistance;
		audioSource.maxDistance = maxDistance;
		audioSource.volume = volume;
		audioSource.clip = audioClip;
		audioSource.loop = loop;
		if (minDistance == 0f && maxDistance == 0f)
		{
			audioSource.spatialBlend = 0f;
		}
		else
		{
			audioSource.spatialBlend = 1f;
		}
		if (playNow)
		{
			audioSource.playOnAwake = true;
			audioSource.Play();
		}
		else
		{
			audioSource.playOnAwake = false;
		}
		if (destroyAfterFinished)
		{
			if ((bool)audioClip)
			{
				Object.Destroy(gameObject, audioClip.length);
			}
			else
			{
				Object.Destroy(gameObject);
			}
		}
		if ((bool)go.transform.Find("All Audio Sources"))
		{
			gameObject.transform.SetParent(go.transform.Find("All Audio Sources"));
		}
		else
		{
			GameObject gameObject2 = new GameObject("All Audio Sources");
			gameObject2.transform.SetParent(go.transform, false);
			gameObject.transform.SetParent(gameObject2.transform, false);
		}
		return audioSource;
	}

	public static void NewHighPassFilter(AudioSource source, float freq, int level)
	{
		if (!(source == null))
		{
			AudioHighPassFilter audioHighPassFilter = source.gameObject.AddComponent<AudioHighPassFilter>();
			audioHighPassFilter.cutoffFrequency = freq;
			audioHighPassFilter.highpassResonanceQ = level;
		}
	}
}
